import axios from "axios";
axios.defaults.headers["Content-Type"] = "application/json";
axios.defaults.headers.get["Content-Type"] =
    "application/x-www-form-urlencoded";
// 创建axios实例
axios.defaults.withCredentials = true;

const service = axios.create({
    // axios中请求配置有baseURL选项，表示请求URL公共部分
     baseURL: '/api',
    // baseURL: "http://47.115.222.115:88",
    // baseURL: "http://139.9.202.40:88",
    //baseURL: "http://localhost:88",
    // 超时
    timeout: 100000,
    withCredentials:true
});
service.interceptors.request.use(
    (config) => {
        let token = localStorage.getItem("Authorization");
        if (token) {
            config.headers = config.headers || {};
            config.headers.Authorization = token || {};
        }
        return config;
    },
    (err) => {
        return Promise.reject(err);
    }
);
axios.interceptors.response.use(function (response) {
    if(response.status==401){
        this.router.push('/signin')
    }
    return response.data;
  }, function (error) {
    return Promise.reject(error);
  });
export default service;